package Aplicacion;
import java.util.Date;

import org.uqbar.commons.utils.ApplicationContext;
import org.uqbar.commons.utils.ApplicationContextConfiguration;
import org.uqbar.commons.utils.MemoryStorage;
import org.uqbar.commons.utils.Storage;

import Homes.CapturasHome;
import Homes.CategoriasHome;
import Mocks.MockAnalizadorSuccess;

public class FotoMultasContext implements ApplicationContextConfiguration {

	//@Override
	public void configure(ApplicationContext instance) {
		installSingletons();
		
		Tipo tipo1= new Tipo("Mal Estacionado",10,11);
		Tipo tipo2= new Tipo("Exceso de velocidad",10,11);
		Infraccion infraccion1 = new Infraccion(tipo1, new Date(), new Zona("5555-5555"));
		Infraccion infraccion2 = new Infraccion(tipo2, new Date(), new Zona("5555-5555"));
		
		Vehiculo vehiculo1 = new Vehiculo("AAA-000");
		Vehiculo vehiculo2 = new Vehiculo("AAA-001");
		Vehiculo vehiculo3 = new Vehiculo("AAA-002");
		
		Captura captura = new Captura(new Imagen(), infraccion1);
		captura.setVehiculo(vehiculo1);
					
		this.makePersistent(Infraccion.class, infraccion1);
		this.makePersistent(Infraccion.class, infraccion2);
		
		this.makePersistent(Vehiculo.class, vehiculo1);
		this.makePersistent(Vehiculo.class, vehiculo2);
		this.makePersistent(Vehiculo.class, vehiculo3);
		
		this.makePersistent(Captura.class, captura);
	}

	// ********************************************************
	// ** Internal
	// ********************************************************

	private <T> T makePersistent(Class<? super T> type, T object) {
		ApplicationContext.getInstance().getHome(type).add(object);
		return object;
	}

	private void installSingletons() {
		ApplicationContext.getInstance().configureSingleton(Storage.class, new MemoryStorage());
		
		CapturasHome capturasHome = new CapturasHome(Captura.class);
		capturasHome.setAnalizadorImagenes(new MockAnalizadorSuccess());
		
		ApplicationContext.getInstance().configureHome(Captura.class, capturasHome);
		ApplicationContext.getInstance().configureHome(Infraccion.class);
		ApplicationContext.getInstance().configureHome(Vehiculo.class);
	}
}
